package org.example;

import java.util.Scanner;

public class Cartest {
    public static void main(String[] args) {
       Car[] arr = new Car[3];
       Scanner sc = new Scanner(System.in);
       for (int i = 0; i < arr.length; i++) {
           Car car = new Car();
           System.out.println("请输入第"+(i+1)+"辆车的品牌：");
           String brand = sc.next();
           car.setBrand(brand);
           System.out.println("请输入第"+(i+1)+"辆车的颜色：");
           String color = sc.next();
           car.setColor(color);
           System.out.println("请输入第"+(i+1)+"辆车的价格：");
           int price = sc.nextInt();
           car.setPrice(price);
           //将car对象存入数组中
           arr[i]=car ;
       }
       int sum =0;
       for (int i = 0; i < arr.length; i++) {
           Car car=arr[i];
           sum += car.getPrice();
           System.out.println("三辆车总共价格为："+sum+"元");
       }
       double avg = sum / arr.length;
       System.out.println("平均价格为："+avg);

       int count = 0;
       for (int i = 0; i < arr.length; i++) {
           Car car = arr[i];
           if (car.getPrice()>avg) {
               count++;
           }
       }
       System.out.println("高于平均价格的车有"+count+"辆");
    }
}
